package com.hmall.order.controller;

import com.hmall.common.dto.ResultDTO;
import com.hmall.order.pojo.Order;
import com.hmall.order.pojo.RequestParams;
import com.hmall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrderController {
    //注入service
    @Autowired
    private OrderService orderService;

    /**
     * 添加订单信息到订单数据中
     *
     * @param params 请求参数
     * @return 返回订单id
     */
    @PostMapping("order")
    public Long addOrder(@RequestBody RequestParams params) {
        return orderService.addOrder(params);
    }

    /**
     * 订单支付
     *
     * @param orderId 订单编号
     * @return
     */
    @PutMapping("/pay/{orderId}")
    public ResultDTO payMoney(@PathVariable("orderId") Long orderId,
                              @RequestBody String password) {
        System.out.println("从前端拿到的密码为: " + password);
        return orderService.payMoney(orderId, password);
    }

    @GetMapping("/order/{id}")
    public Order findOrderById(@PathVariable("id") Long id){
        return orderService.findOrderById(id);
    }

}
